import wx
from wx.lib.pubsub import setuparg1
from wx.lib.pubsub import pub


PANEL_VIEW_TIME_ALL = 0
PANEL_VIEW_TIME_DAY = 1
PANEL_VIEW_TIME_WEEK = 2
PANEL_VIEW_TIME_MONTH = 4

class ListSubPanel(wx.Panel):
    icons = ("res/all.png", "res/day.png", "res/week.png", "res/month.png")
    def __init__(self, parent):
        wx.Panel.__init__(self, parent = parent)
        sizer = self.sizer = wx.BoxSizer(wx.VERTICAL)
        handlers = self.return_handlers()

        for i, h in zip(self.icons, handlers):
            pic = wx.Image(i, wx.BITMAP_TYPE_PNG).ConvertToBitmap()
            b = wx.BitmapButton(self, -1, pic)
            b.Bind(wx.EVT_BUTTON, h)
            sizer.Add(b)

        self.SetSizer(sizer)

    def return_handlers(self):
        #those with unsual button layout shoud overide this
        return (self.on_all, self.on_day, self.on_week, self.on_month)

    def on_all(self,evt):
        pub.sendMessage(self.M_TIME_CHANGE, data=PANEL_VIEW_TIME_ALL)

    def on_day(self,evt):
        pub.sendMessage(self.M_TIME_CHANGE, data=PANEL_VIEW_TIME_DAY)

    def on_week(self,evt):
        pub.sendMessage(self.M_TIME_CHANGE, data=PANEL_VIEW_TIME_WEEK)

    def on_month(self,evt):
        pub.sendMessage(self.M_TIME_CHANGE, data=PANEL_VIEW_TIME_MONTH)

class PanelRecord(ListSubPanel):
    """
    PanelRecord has heavily overiden ListSubPanel
    """
    M_TIME_CHANGE = ("RECORD", "TIME_MODE_CHANGED")
    M_VIEW_MODE_CHANGE = ("RECORD", "VIEW_MODE_CHANGED")
    
    icons = ("res/day.png", "res/week.png", "res/month.png",
             "res/pie.png", "res/trend.png", "res/list.png")

    def return_handlers(self):
        return (self.on_day, self.on_week, self.on_month,
                self.on_pie, self.on_trend, self.on_list)

    def on_pie(self, evt):
        pub.sendMessage(self.M_VIEW_MODE_CHANGE, data='P')

    def on_trend(self, evt):
        pub.sendMessage(self.M_VIEW_MODE_CHANGE, data='T')

    def on_list(self, evt): 
        pub.sendMessage(self.M_VIEW_MODE_CHANGE, data='L')

class PanelTodo(ListSubPanel):
    M_TIME_CHANGE = ("PANELTODO","TIME_CHANGED")
    M_TODO_TOGGLE_VIEW = ("TODO", "TOGGLE_VIEW_MODE")
    def __init__(self, parent):
        ListSubPanel.__init__(self, parent)
        pic = wx.Image("res/view.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        b = wx.BitmapButton(self, -1, pic)
        b.Bind(wx.EVT_BUTTON, self.on_toggle_mode)
        self.sizer.Add(b)
        self.view_mode = 0 #list mode
    def on_toggle_mode(self, evt):
        #list or calendar
        #we simple need to tell main view that mode should be toggled
        pub.sendMessage(self.M_TODO_TOGGLE_VIEW, data=None)

class PanelCollect(ListSubPanel):
    M_TIME_CHANGE = ("PANELCOLLECT","TIME_CHANGED")
    
class PanelWish(ListSubPanel):
    M_TIME_CHANGE = ("PANELWISH","TIME_CHANGED")



if __name__ == '__main__':
    app = wx.App()
    f = wx.Frame(None)
    p = TodoSubPanel(f)
    f.Show()
    app.MainLoop()
